const system = {
	state: {
		// 网络状态 （0 内网， 1 外网）
		networkStatus: uni.getStorageSync('networkStatus') || 1, // 默认外网
		// 登录是否过期 
		expired: false
	},

	mutations: {
		SET_NETWORK_STATUS: (state, value) => {
			state.networkStatus = value
			uni.setStorageSync('networkStatus', JSON.stringify(value))
		},
		SET_EXPIRED: (state, value) => {
			console.log('SET_EXPIRED', value);
			state.expired = value
		}
	},

	actions: {
		toggleNetworkStatus({
			commit,
			state
		}) {
			commit('SET_NETWORK_STATUS', state.networkStatus == 1 ? 0 : 1)
			uni.setStorageSync('toggleNetworkStatus', 1)
			// #ifdef APP-PLUS
			plus.runtime.restart();
			// #endif
			// #ifdef H5
			window.location.reload()
			// #endif
		},
		setExpired({commit}, value) {
			commit('SET_EXPIRED', value)
		}
	},
}

export default system